package ch8.replaceArrayWithObject;

import java.util.Dictionary;
import java.util.Hashtable;

public class Customer {
    private static Dictionary _instances = new Hashtable();

    private final String _name;


    private Customer(String name){
        this._name = name;
    }
    public static Customer create(String name){
        return getNamed(name);
    }

    public static Customer getNamed(String name){
        return (Customer) _instances.get(name);
    }

    public String getName() {
        return _name;
    }


    static void loadCustomers(){
        new Customer("Lemon Car Hire").store();
        new Customer("Associated Coffee Machines").store();
        new Customer("Bilston Gasworks").store();
    }

    public void store(){
        this._instances.put(this.getName(), this);
    }


}
